<template></template>
<script lang="ts" setup>
    import { ElMessage, ElMessageBox } from 'element-plus'

    const props = defineProps({
        title: {
            type: String,
            default:'警告'
        },
        message: {
            type: String,
            default: '该记录将被删除，是否继续？'
        },
        confirmButtonText: {
            type: String,
            default: '确认'
        },
        cancelButtonText: {
            type: String,
            default: '取消'
        },
        successMessage: {
            type: String,
            default: '删除成功'
        },
        infoMessage: {
            type: String,
            default: '取消删除'
        }
    })
    /**
     * 消息弹出框
     */
    const openMessageBox = () => {
        ElMessageBox.confirm(
            props.message,
            props.title,
            {
                confirmButtonText: props.confirmButtonText,
                cancelButtonText: props.cancelButtonText,
                type: 'warning',
            }
        )
        .then(() => {
            emits('confirm', {
                callback: (result: any) => {
                    if(result) {
                        ElMessage({
                            type: 'success',
                            message: props.successMessage,
                        })
                    }
                }
            }) 
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: props.infoMessage,
            })
        })
    }
    /**
     * 定义发射给父组件的方法
     */
    const emits = defineEmits(['confirm'])
     /**
     * 暴露方法
     */
	defineExpose({
        openMessageBox,
	})
</script>
<style scoped></style>